import axios from 'axios';
/**
 * 使用第三方服务(获取公网IP)
 */
export const getIPs = (callback) => {
    axios.get('https://api.ipify.org').then(res => {
        callback(res.data)
    })
}
/**
 * 全球唯一标识符
 */
export const getGuid = () => {
    let guid = getCookie('guid')
    if (guid != null && guid !== "") {
        return guid
    } else {
        guid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
            let r = Math.random()*16|0
            let v = c === 'x' ? r : (r&0x3|0x8);
            return v.toString(16);
        });
        if (guid !== null && guid !== "") {
            setCookie('guid', guid, 365)
        }
        return guid
    }
}
/**
 *
 * @param keyCode 默认13 回车按钮
 * @param callback
 */
export const keyupButton = (keyCode = 13, callback) => {
    document.onkeydown = e => {
        let body = document.getElementsByTagName('body')[0]
        if (e.keyCode === 13 && e.target.baseURI.match('/') && e.target === body) {
            callback()
        }
    }
}

/**
 * 判断是否为iOS
 */
export const isIOS = () => {
    let u = navigator.userAgent;
    let isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); // ios终端
    return isiOS
}
/**
 * 判断是否为Android
 */
export const isAndroid = () => {
    let u = navigator.userAgent;
    let isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; // android终端
    return isAndroid
}